********************************************************************************
*Project:  	Swiss Trade During the Covid-19 Pandemic: An Early Appraisal	
*Authors:	KB, SL, VP, PW											
*This File: Figure 2
*Version: 	vFINAL							
*Date: 		2020-09-01				
********************************************************************************

********************************************************************************
*1. Cumulative Imports and Exports Comparison with Previous Years
********************************************************************************

* I. Import and Prepare Data 

use "${root}\workfiles\trade_2002_2020_analysis.dta", replace

keep if SAMPLE==99

keep if inrange(jahr, 2017, 2020)

collapse (sum) handel_chf_mia, by(handel_typ jahr woche datum_mo)

sum woche if jahr == 2020
local maximum = r(max)

keep if inrange(woche, 1, 30)

* II. Create Plots

sort jahr woche
	
bysort jahr: gen cum_imports = sum(handel_chf_mia) if handel_typ == "I"
bysort jahr: gen cum_exports = sum(handel_chf_mia) if handel_typ == "E"

graph twoway	(line cum_imports woche if handel_typ == "I" & jahr == 2020, lcolor(black) lwidth(medthick) lpattern(solid)) ///
				(line cum_imports woche if handel_typ == "I" & jahr == 2019, lcolor(gs4) lwidth(medium) lpattern(longdash)) ///
				(line cum_imports woche if handel_typ == "I" & jahr == 2018, lcolor(gs7) lwidth(medium) lpattern(dash)) ///
				(line cum_imports woche if handel_typ == "I" & jahr == 2017, lcolor(gs10) lwidth(medium) lpattern(shortdash) ///
				ytitle("Trade in Billion CHF") xtitle("Calendar Week") ///
				yscale(range (-10 150)) xscale(range (0 30)) ylabel(0(50)150,nogrid) xlabel(0(5)30,nogrid) ///
				xline(12, lcolor(maroon)) text(11 11 "Swiss Lockdown", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(18, lcolor(maroon) lpattern(dash) lwidth(thin)) text(5 17 "Relaxation 1", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(20, lcolor(maroon) lpattern(dash) lwidth(thin)) text(5 19 "Relaxation 2", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(24, lcolor(maroon) lpattern(dash) lwidth(thin)) text(5 23 "Relaxation 3", size(small) place(e) orient(vertical) color(maroon)) ///
				scheme(s1color) ///
				legend(label(1 "Cumulative Imports 2020") label(2 "Cumulative Imports 2019") ///
				label(3 "Cumulative Imports 2018") label(4 "Cumulative Imports 2017")))

graph export "${root}\figures\FIG2a_cum_agg_imports_byCW_2017-2020.png", replace	width(1600) height(1200)
graph export "${root}\figures\FIG2a_cum_agg_imports_byCW_2017-2020.pdf", replace	


graph twoway	(line cum_exports woche if handel_typ == "E" & jahr == 2020, lcolor(black) lwidth(medthick) lpattern(solid)) ///
				(line cum_exports woche if handel_typ == "E" & jahr == 2019, lcolor(gs4) lwidth(medium) lpattern(longdash)) ///
				(line cum_exports woche if handel_typ == "E" & jahr == 2018, lcolor(gs7) lwidth(medium) lpattern(dash)) ///
				(line cum_exports woche if handel_typ == "E" & jahr == 2017, lcolor(gs10) lwidth(medium) lpattern(shortdash) ///
				ytitle("Trade in Billion CHF") xtitle("Calendar Week") ///
				yscale(range (-10 150)) xscale(range (0 30)) ylabel(0(50)150,nogrid) xlabel(0(5)30,nogrid) ///
				xline(12, lcolor(maroon)) text(11 11 "Swiss Lockdown", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(18, lcolor(maroon) lpattern(dash) lwidth(thin)) text(5 17 "Relaxation 1", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(20, lcolor(maroon) lpattern(dash) lwidth(thin)) text(5 19 "Relaxation 2", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(24, lcolor(maroon) lpattern(dash) lwidth(thin)) text(5 23 "Relaxation 3", size(small) place(e) orient(vertical) color(maroon)) ///
				scheme(s1color) ///
				legend(label(1 "Cumulative Exports 2020") label(2 "Cumulative Exports 2019") ///
				label(3 "Cumulative Exports 2018") label(4 "Cumulative Exports 2017")))

graph export "${root}\figures\FIG2b_cum_agg_exports_byCW_2017-2020.png", replace	width(1600) height(1200)
graph export "${root}\figures\FIG2b_cum_agg_exports_byCW_2017-2020.pdf", replace	


********************************************************************************
*2. Difference 2020 vs 2019
********************************************************************************

// (i) Total Difference


// Imports
	
gen helpvar1 = cum_imports if jahr == 2020
bysort woche: egen cum_imports2020 = sum(helpvar1)

gen helpvar2 = cum_imports if jahr == 2019
bysort woche: egen cum_imports2019 = sum(helpvar2)

gen helpvar3 = cum_imports if jahr == 2018
bysort woche: egen cum_imports2018 = sum(helpvar3)

gen helpvar4 = cum_imports if jahr == 2017
bysort woche: egen cum_imports2017 = sum(helpvar4)

drop helpvar*

gen d_cum_imports_2020_2019 = cum_imports2020 - cum_imports2019
gen d_cum_imports_2020_2018 = cum_imports2020 - cum_imports2018
gen d_cum_imports_2020_2017 = cum_imports2020 - cum_imports2017


// Exports

gen helpvar1 = cum_exports if jahr == 2020
bysort woche: egen cum_exports2020 = sum(helpvar1)

gen helpvar2 = cum_exports if jahr == 2019
bysort woche: egen cum_exports2019 = sum(helpvar2)

gen helpvar3 = cum_exports if jahr == 2018
bysort woche: egen cum_exports2018 = sum(helpvar3)

gen helpvar4 = cum_exports if jahr == 2017
bysort woche: egen cum_exports2017 = sum(helpvar4)

drop helpvar*

gen d_cum_exports_2020_2019 = cum_exports2020 - cum_exports2019
gen d_cum_exports_2020_2018 = cum_exports2020 - cum_exports2018
gen d_cum_exports_2020_2017 = cum_exports2020 - cum_exports2017


graph twoway	(line d_cum_imports_2020_2019 woche if handel_typ == "I" & jahr == 2020, lcolor(gs2) lwidth(medium) lpattern(longdash)) ///
				(line d_cum_imports_2020_2018 woche if handel_typ == "I" & jahr == 2020, lcolor(gs6) lwidth(medium) lpattern(dash)) ///
				(line d_cum_imports_2020_2017 woche if handel_typ == "I" & jahr == 2020, lcolor(gs10) lwidth(medium) lpattern(shortdash) ///
				ytitle("Difference 2020 vs Prior Years (Billion CHF)") xtitle("Calendar Week") ///
				yscale(range (-20 5)) xscale(range (0 30)) ylabel(-20(5)5,nogrid) xlabel(0(5)30,nogrid) ///
				xline(12, lcolor(maroon)) text(-16.6 11 "Swiss Lockdown", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(18, lcolor(maroon) lpattern(dash) lwidth(thin)) text(-17.7 17 "Relaxation 1", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(20, lcolor(maroon) lpattern(dash) lwidth(thin)) text(-17.7 19 "Relaxation 2", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(24, lcolor(maroon) lpattern(dash) lwidth(thin)) text(-17.7 23 "Relaxation 3", size(small) place(e) orient(vertical) color(maroon)) ///
				scheme(s1color) ///
				legend(subtitle("Cumulative Difference in Imports", size(medsmall)) ///
				order(1 "2020 – 2019" 2 "2020 – 2018" 3 "2020 – 2017") symxsize(*0.68) cols(3) rows(1)))

graph export "${root}\figures\FIG_APP_cum_agg_imports_byCW_2017-2020_difference.pdf", replace	


graph twoway	(line d_cum_exports_2020_2019 woche if handel_typ == "I" & jahr == 2020, lcolor(gs2) lwidth(medium) lpattern(longdash)) ///
				(line d_cum_exports_2020_2018 woche if handel_typ == "I" & jahr == 2020, lcolor(gs6) lwidth(medium) lpattern(dash)) ///
				(line d_cum_exports_2020_2017 woche if handel_typ == "I" & jahr == 2020, lcolor(gs10) lwidth(medium) lpattern(shortdash) ///
				ytitle("Difference 2020 vs Prior Years (Billion CHF)") xtitle("Calendar Week") ///
				yscale(range (-20 5)) xscale(range (0 30)) ylabel(-20(5)5,nogrid) xlabel(0(5)30,nogrid) ///
				xline(12, lcolor(maroon)) text(-16.6 11 "Swiss Lockdown", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(18, lcolor(maroon) lpattern(dash) lwidth(thin)) text(-17.7 17 "Relaxation 1", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(20, lcolor(maroon) lpattern(dash) lwidth(thin)) text(-17.7 19 "Relaxation 2", size(small) place(e) orient(vertical) color(maroon)) ///
				xline(24, lcolor(maroon) lpattern(dash) lwidth(thin)) text(-17.7 23 "Relaxation 3", size(small) place(e) orient(vertical) color(maroon)) ///
				scheme(s1color) ///
				legend(subtitle("Cumulative Difference in Exports", size(medsmall)) ///
				order(1 "2020 – 2019" 2 "2020 – 2018" 3 "2020 – 2017") symxsize(*0.68) cols(3) rows(1)))

graph export "${root}\figures\FIG_APP_cum_agg_exports_byCW_2017-2020_difference.pdf", replace	





